import Vue from 'vue';
import VueRouter from 'vue-router';

import {
    Home,
    First,
    Info,
    Dynamic,
    Notice,
    Result,
    Person,
    File,
    Topic,
    Choose,
    Main,
    Content
} from './pages';

Vue.use(VueRouter);

const routes = [
    {
        path:'/',
        redirect:'/home/first'
    },
    {
        path:'/home',
        component:Home,
        name:'home',
        children:[
            {
                path:'first',
                component:First,
                name:'first'
            },
            {
                path:'info',
                component:Info,
                name:'info'
            },
            {
                path:'dynamic',
                component:Dynamic,
                name:'dynamic'
            },
            {
                path:'notice',
                component:Notice,
                name:'notice'
            },
            {
                path:'result',
                component:Result,
                name:'result'
            },
            {
                path:'person',
                component:Person,
                name:'person'
            },
            {
                path:'file',
                component:File,
                name:'file'
            },
            {
                path:'content',
                component:Content,
                name:'content'
            }
        ]
    },
    {
        path:'/topic',
        component:Topic,
        name:'topic',
        children:[
            {
                path:'choose',
                component:Choose,
                name:'choose'
            },
            {
                path:'main',
                component:Main,
                name:'main'
            }
        ]
    }
];

export const router = new VueRouter({
   routes
});
router.beforeEach((to, from, next) => {
    Vue.prototype.$loading();
    next();
});
router.afterEach(route => {
    if (route.name != 'main') {
        Vue.prototype.$loading.close();
    }
});